package test3;

import java.util.concurrent.Semaphore;

public class Tourist extends Thread{
    private Semaphore semaphore;
    @Override
    public void run() {
        try {
            semaphore.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"进行参观");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+"在2秒之后,退出展览室");
        semaphore.release();
    }

    public Tourist(Semaphore semaphore) {
        this.semaphore=semaphore;
    }
}
